{% extends 'authentication/auth_base.html' %}
{% block title %} 登入 - 黑熊平台 {% endblock %}

{% block content %}
    <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

        <div class="layadmin-user-login-main">
            <div class="layadmin-user-login-box layadmin-user-login-header">
                <h2>黑熊平台</h2>
                <p>后台管理系统</p>
            </div>
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                           for="LAY-user-login-username"></label>
                    <input type="text" name="name" id="LAY-user-login-username" lay-verify="required" placeholder="用户名"
                           class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                           for="LAY-user-login-password"></label>
                    <input type="password" name="password" id="LAY-user-login-password" lay-verify="required"
                           placeholder="密码" class="layui-input">
                </div>

                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-xs7">
                            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"
                                   for="LAY-user-login-vercode"></label>
                            <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required"
                                   placeholder="图形验证码" class="layui-input">
                        </div>
                        <div class="layui-col-xs5">
                            <div style="margin-left: 10px;">
                                <img src="{{ url_for('auther.validate_code') }}" id="validate">
                            </div>
                        </div>
                    </div>
                </div>

            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登 入</button>
            </div>

            <div class="layui-trans layui-form-item layadmin-user-login-other">
                <label>预留</label>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>

                <a href="{{ url_for('auther.register') }}" class="layadmin-user-jump-change layadmin-link">注册帐号</a>
            </div>

        </div>
    </div>
    </div>
{% endblock %}


{% block script %}

    {{ super() }}
    <script>
        // 加载模块 form
        layui.use('form', function () {
            var form = layui.form;
            form.render();    // 更新全部
            form.on('submit(LAY-user-login-submit)', function (obj) {
                var field = obj.field;
                $.ajax({
                    url: '{{ url_for("auther.login") }}',
                    type: "post",
                    data: field,
                    success: function (data) {
                        if (data.code == 10000) {
                            window.open(data.url, '_self');
                        } else if (data.code == 10001) {
                            layer.msg('帐号或密码错误,请重新输入', {icon: 5})
                        } else if (data.code == 10002) {
                            layer.msg('帐户未被激活, 请联系管理员激活', {icon: 5})
                        } else if (data.code == 10003){
                            layer.msg('验证码不正确，请重新输入', {icon: 5})
                        }
                    }
                })
            })
        })
    $("#validate").on('click', function () {
        $.ajax({
            url: '{{ url_for("auther.validate_code") }}',
            type:"get",
            success: function (data) {
                $("#validate").attr('src',"{{ url_for('auther.validate_code') }}")
            }
        })
    })

    </script>
{% endblock %}
